//
//  TimeMainHomeVC.m
//  Doctor
//
//  Created by 阳光 on 16/9/6.
//  Copyright © 2016年 阳光. All rights reserved.
//

#import "TimeMainHomeVC.h"
#import "FirstDocCell.h"
#import "VisitDocCell.h"


#import "TodayOrderCell.h"
#import "TodayConsultCell.h"
#import "TodayOperationCell.h"

#import "MessageListVC.h"

#define selectViewH  45

static NSString *todayOrderCellIdentifier=@"TodayOrderCellIdentifier";
static NSString *todayConsultCellIdentifier=@"TodayConsultCellIdentifier";
static NSString *todayOperationCellIdentifier=@"TodayOperationCellIdentifier";



@interface TimeMainHomeVC ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UIView *downLine;

@property(nonatomic,assign)NSInteger currentIndex;

@property(nonatomic,strong)UIScrollView *mainScrollView;

// 初诊
@property(nonatomic,strong)UITableView *firstDocTableView;

// 就诊
@property(nonatomic,strong)UITableView *visitDocTableView;


@end

@implementation TimeMainHomeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title=@"时间";
    
    [self initSelectView];
    
    [self initTableView];
    
    [self initNavBarBtnItem];
    
    [self getLoad];
}

-(void)initNavBarBtnItem
{
    // 添加论文
    self.navigationItem.rightBarButtonItem=[UIBarButtonItem initWithNormalImage:@"message" target:self action:@selector(messageItemEvent)];
}


-(void)messageItemEvent
{
    // 跳转到消息列表界面
    MessageListVC *messageListVC=[MessageListVC new];
    [self.navigationController pushViewController:messageListVC animated:NO];
}

-(void)initScrollView
{
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    _mainScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,110,APPW,APPH-110)];
    _mainScrollView.backgroundColor=ClearColor;
    _mainScrollView.showsHorizontalScrollIndicator=NO;
    _mainScrollView.pagingEnabled=YES;
    _mainScrollView.delegate=self;
    _mainScrollView.contentSize=CGSizeMake(APPW*3,APPH-125);
    [self.view addSubview:_mainScrollView];

}

-(void)getLoad
{
    
}

-(void)initTableView
{
    // _firstDocTableView
    _firstDocTableView=[[UITableView alloc]initWithFrame:CGRectMake(0,selectViewH,APPW,APPH-selectViewH) style:UITableViewStylePlain];
    _firstDocTableView.delegate=self;
    _firstDocTableView.dataSource=self;
    _firstDocTableView.hidden=NO;
    _firstDocTableView.backgroundColor=MAIN_BACK_COLOR;
    _firstDocTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_mainScrollView addSubview:_firstDocTableView];
    [_firstDocTableView registerClass:[TodayOrderCell class] forCellReuseIdentifier:todayOrderCellIdentifier];
    
    // _firstDocTableView
    _visitDocTableView=[[UITableView alloc]initWithFrame:CGRectMake(APPW,selectViewH,APPW,APPH-selectViewH) style:UITableViewStylePlain];
    _visitDocTableView.delegate=self;
    _visitDocTableView.dataSource=self;
    _visitDocTableView.hidden=YES;
    _visitDocTableView.backgroundColor=MAIN_BACK_COLOR;
    _visitDocTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_mainScrollView addSubview:_visitDocTableView];
    [_visitDocTableView registerClass:[TodayConsultCell class] forCellReuseIdentifier:todayConsultCellIdentifier];
    
    {
        _firstDocTableView=[[UITableView alloc]initWithFrame:CGRectMake(APPW*2,selectViewH,APPW,APPH-selectViewH) style:UITableViewStylePlain];
        _firstDocTableView.delegate=self;
        _firstDocTableView.dataSource=self;
        _firstDocTableView.hidden=NO;
        _firstDocTableView.backgroundColor=MAIN_BACK_COLOR;
        _firstDocTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_mainScrollView addSubview:_firstDocTableView];
        [_firstDocTableView registerClass:[TodayOrderCell class] forCellReuseIdentifier:todayOrderCellIdentifier];
    }
    
}


-(void)initSelectView
{
    //标题
    UIView *titleView=[[UIView alloc]initWithFrame:CGRectMake(0,0,APPW,selectViewH)];
    titleView.backgroundColor=Color5C6E7C;
    [self.view addSubview:titleView];
    
    NSArray *titleArr=@[@"今日预约",@"今日咨询",@"今日手术"];
    for (int i=0;i<titleArr.count;i++)
    {
        UIButton *titleArrBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        titleArrBtn.frame = CGRectMake(APPW/3.0*i,0,APPW/3.0,selectViewH);
        [titleArrBtn setTitle:titleArr[i] forState:UIControlStateNormal];
        [titleArrBtn setTitleColor:WhiteColor forState:0];
        titleArrBtn.titleLabel.font=Font_Number(16);
        [titleArrBtn addTarget:self action:@selector(titleArrBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
        titleArrBtn.tag=10+i;
        if (i==0)
        {
            titleArrBtn.backgroundColor=Main_Color;
            titleArrBtn.selected=YES;
        }
        [titleView addSubview:titleArrBtn];
    }

}


-(void)titleArrBtnEvent:(UIButton *)sender
{
    NSInteger tag=sender.tag;
    _currentIndex=tag-10;
    _mainScrollView.contentOffset=CGPointMake(APPW*_currentIndex,0);
    
    for (int i=10;i<13;i++)
    {
        UIButton *button=(UIButton *)[self.view viewWithTag:i];
        if (i==tag)
        {
            button.selected=YES;
            button.backgroundColor=Main_Color;
        }
        else
        {
            button.selected=NO;
            button.backgroundColor=Color5C6E7C;
        }
    }
    
}

//-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
//{
//    CGPoint pt = _mainScrollView.contentOffset;
//    
//    _currentIndex=pt.x/APPW;
//    
//  
//    NSInteger tag=10+_currentIndex;
//    
//    for (int i=10;i<13;i++)
//    {
//        UIButton *btn=(UIButton *)[self.view viewWithTag:i];
//        if (i == tag)
//        {
//            btn.selected=YES;
//        }
//        else
//        {
//            btn.selected=NO;
//        }
//    }
//    
//}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView==_firstDocTableView)
    {
        return 1;
    }
    else
    {
        return 1;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_firstDocTableView)
    {
        TodayOrderCell *cell=[tableView dequeueReusableCellWithIdentifier:todayOrderCellIdentifier];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
    }
    else
    {
        TodayConsultCell *cell=[tableView dequeueReusableCellWithIdentifier:todayConsultCellIdentifier];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;

    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_firstDocTableView)
    {
        return 334/2;
    }
    else
    {
        return (162+20)/2;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
//    PatientInfoVC *patientInfoVC=[PatientInfoVC new];
//    [self.navigationController pushViewController:patientInfoVC animated:NO];
    
}


@end
